package com.alibaba.citrus.cr.platform.enhance.functions.diff.common.dataParser;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.citrus.cr.platform.enhance.functions.diff.activity.constant.ActivityDiffStandardFieldDict;
import com.alibaba.citrus.cr.platform.enhance.functions.diff.common.constant.SalesOrderLineDiffStandardFieldDict;
import com.alibaba.citrus.cr.platform.enhance.repository.model.diff.common.FieldLineDTO;
import com.alibaba.citrus.cr.platform.enhance.repository.model.diff.common.SalesOrderLineDTO;
import com.alibaba.cz.base.tool.log.Log;

import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Component;

/**
 * @author hanguo
 * @date 2022/1/19
 * @Description 销售子单解析器
 */
@Component
public class SalesOrderLineDataParse extends DataParser {

    /**
     * 日志
     */
    private static Log log = Log.getLogger(SalesOrderLineDataParse.class);

    /**
     * 数据库字段，映射成对账处理的业务字段(标准字段)
     * key：数据库中的字段，value：转换后的标准字段,这里的 value 字段也不要重复
     */
    private static Map<String, String> dataBaseFiledMapping = new HashedMap();

    static {
        dataBaseFiledMapping.put("scItemOutCode", ActivityDiffStandardFieldDict.ITEM_ID.getFieldCode());
        dataBaseFiledMapping.put("frontOrderLineId",ActivityDiffStandardFieldDict.SUB_ORDER_ID.getFieldCode());
        dataBaseFiledMapping.put("activityPrice", SalesOrderLineDiffStandardFieldDict.SPECIAL_OFFER_PRICE.getFieldCode());
        dataBaseFiledMapping.put("quantity",SalesOrderLineDiffStandardFieldDict.ITEM_QUANTITY.getFieldCode());
        dataBaseFiledMapping.put("unitPrice", SalesOrderLineDiffStandardFieldDict.UNIT_PRICE.getFieldCode());
        dataBaseFiledMapping.put("refuseReasonCode", SalesOrderLineDiffStandardFieldDict.REFUSE_REASON_CODE.getFieldCode());

        //该字段不需要核对
        //dataBaseFiledMapping.put(orderLineDTO.getActivityName(),);
        dataBaseFiledMapping.put("activityCode", ActivityDiffStandardFieldDict.ACTIVITY_ID.getFieldCode());
        dataBaseFiledMapping.put("features.activityNumber",ActivityDiffStandardFieldDict.ACTIVITY_TERM_ID.getFieldCode());
        dataBaseFiledMapping.put("features.sequenceNo",ActivityDiffStandardFieldDict.SEQUENCE_NO.getFieldCode());


        dataBaseFiledMapping.put("serialNumber",SalesOrderLineDiffStandardFieldDict.SERIAL_NUMBER.getFieldCode());
        dataBaseFiledMapping.put("outerOrderLineId",SalesOrderLineDiffStandardFieldDict.SAP_SALES_ORDER_LINE_ID.getFieldCode());
        dataBaseFiledMapping.put("saleUnit",SalesOrderLineDiffStandardFieldDict.SALE_UNIT.getFieldCode());
        dataBaseFiledMapping.put("shouldPayFee",SalesOrderLineDiffStandardFieldDict.SUB_TOTAL_AMOUNT.getFieldCode());
        dataBaseFiledMapping.put("returnCharacter",SalesOrderLineDiffStandardFieldDict.RETURN_FLAG.getFieldCode());
        //dataBaseFiledMapping.put("refuseReasonName",SalesOrderLineDiffStandardFieldDict.REFUSE_REASON_NAME.getFieldCode());

    }


    @Override
    public Map<String, FieldLineDTO> parse(Object obj) {
        Map<String, FieldLineDTO> map = new HashMap<>();
        if (obj instanceof SalesOrderLineDTO) {
            SalesOrderLineDTO salesOrderLineDTO = (SalesOrderLineDTO) obj;
            return obtainFieldLineMap(dataBaseFiledMapping, salesOrderLineDTO, salesOrderLineDTO.getClass());
        }
        return map;
    }

    @Override
    public String obtainProcessType() {
        return "SalesOrderLineDTO";
    }
}
